/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulator.network;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import org.tc33.jheatchart.HeatChart;

/**
 *
 * @author Pascal Schwenke <pascal.schwenke@gmail.com>
 */
public class Output {

    public static void NetworkToHeatmap(Network n, String title, String pathName) throws IOException {
        double[][] data = new double[10][10];
        int counter = 0;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                data[i][j] = n.cells.get(counter).userCount;
                counter++;
            }
        }

        // Create our heat map chart using our data.
        HeatChart map = new HeatChart(data);

        // Customise the chart.
        map.setTitle(title);
        map.setXAxisLabel("longitude");
        map.setYAxisLabel("latitude");

        //Set red as representation of high values and blue for low values
        map.setHighValueColour(Color.RED);
        map.setLowValueColour(Color.BLUE);

        // Output the chart to a file.
        map.saveToFile(new File(pathName));
    }

    public static String NetworkCellTypesToString(Network n) {
        String networkCellTypes = "\n";
        for (int i = 0; i < n.cells.size(); i++) {
            networkCellTypes += Character.toUpperCase(n.GetCellById(i).type.charAt(0)) + " ";
            if (n.GetCellById(i).id % 10 == 0) {
                networkCellTypes += "\n";
            }
        }
        return networkCellTypes;
    }

    public static String NetworkUserCountToString(Network n) {
        String networkUserCount = "\n";
        for (int i = 1; i <= n.cells.size(); i++) {
            networkUserCount +=(int) n.GetCellById(i).userCount + " ";
            if (n.GetCellById(i).id % 10 == 0) {
                networkUserCount += "\n";
            }
        }
        return networkUserCount;
    }

    public static String NetworkNeighborCountToString(Network n) {
        String networkNeighborCount = "\n";
        for (int i = 0; i < n.cells.size(); i++) {
            networkNeighborCount += n.GetCellById(i).neighbors.length + " ";
            if (n.GetCellById(i).id % 10 == 0) {
                networkNeighborCount += "\n";
            }
        }
        return networkNeighborCount;
    }
    /*
     public static String NetworkToString(Network n) {
     String NetworkString = "\n";
     for (int i = 0; i < n.height; i++) {
     for (int j = 0; j < n.width; j++) {
     NetworkString += n.GetCell(i, j).id + ";" + n.GetCell(i, j).longitude + ";" + n.GetCell(i, j).latitude + ";" + n.GetCell(i, j).type + ";" + n.GetCell(i, j).userCount + ";";
     for (int k = 0; k < n.GetCell(i, j).neighbors.length; k++) {
     NetworkString += n.GetCell(i, j).neighbors[k];
     if (k < n.GetCell(i, j).neighbors.length - 1) {
     NetworkString += ",";
     }
     }
     NetworkString += "\n";
     }
     }
     return NetworkString;
     }

     public static String TestTransitionRules(Network n) {
     String TestTransitionRules = "\n";
     for (int i = 0; i < n.height; i++) {
     for (int j = 0; j < n.width; j++) {
     for (int k = 0; k < n.GetCell(i, j).neighbors.length; k++) {
     for (int l = 1; l < 8; l++) {
     TestTransitionRules += n.GetCell(i, j).id + ";" + n.GetCell(i, j).neighbors[k] + ";" + "0;5;" + l + ";0;";
     TestTransitionRules += "\n";
     TestTransitionRules += n.GetCell(i, j).id + ";" + n.GetCell(i, j).neighbors[k] + ";" + "6;12;" + l + ";0;";
     TestTransitionRules += "\n";
     TestTransitionRules += n.GetCell(i, j).id + ";" + n.GetCell(i, j).neighbors[k] + ";" + "13;19;" + l + ";0;";
     TestTransitionRules += "\n";
     TestTransitionRules += n.GetCell(i, j).id + ";" + n.GetCell(i, j).neighbors[k] + ";" + "20;0;" + l + ";0;";
     TestTransitionRules += "\n";
     }
     }
     }
     }
     return TestTransitionRules;
     }

     */
}
